package org.paychina.demo;

import java.util.Arrays;

import org.apache.commons.lang.StringUtils;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;

/**
 * 计算DEMO
 * @author Warmsheep
 *
 */
public class CalculateActor {

	
	public static void main(String[] args) {
		//Spark配置
		SparkConf sparkConf = new SparkConf();
		sparkConf.set("spark.app.name", "FilterActor");
		sparkConf.set("spark.master", "local[1]");
		sparkConf.set("spark.ui.port", "36000"); //# 重载默认端口配置
		
		JavaSparkContext ctx = new JavaSparkContext(sparkConf);	
		//申明需要计算的对象
		JavaRDD<Double> calRDD = ctx.parallelize(Arrays.asList(1.0, 50.0, 80.0, 9.0, 2.2, 33.0, 2.0));
		
		//进行平方计算
		JavaRDD<Double> resultRDD = calRDD.map(new Function<Double, Double>() {
			@Override
			public Double call(Double x) throws Exception {
				return x * x; 
			}
		});
		
		System.out.println(StringUtils.join(resultRDD.collect(), ","));
		
	}
}
